<?php
// +----------------------------------------------------------------------
// | sfadmin - Suifeng Administration
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2020 http://suifeng.tech All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: suifeng <1787585212@qq.com>
// +----------------------------------------------------------------------

namespace app\wechat\common;

use app\admin\common\AdminController;

class AdminWxController extends AdminController
{
    protected $mp_id;
    protected $mp_number;
    protected $current_mp;

    protected function _initialize()
    {
        parent::_initialize();

        // 先检查mp_id有没有作为输入参数传递进来
        $this->mp_id = input('mp_id');

        // 如果再检查session
        if (empty($this->mp_id)) {
            $this->mp_id = session('mp_id');
        }

        // 最后从数据库里面获取
        if (empty($this->mp_id)) {
            $this->mp_id = model('wechat/mp')->min('id');
        }

        $this->current_mp = model('wechat/mp')->where('id', $this->mp_id)->find();
        if (!$this->current_mp) {
            helper('admin/flash')->warn('未定义微信公众号。');
            $this->redirect(url('wechat/admin.mp/index'));
        }

        $this->mp_number = $this->current_mp['mp_number'];

        session('mp_id', $this->mp_id);
        session('mp_number', $this->mp_number);
        $this->assign('mp_id', $this->mp_id);
        $this->assign('mp_number', $this->mp_number);
        $this->assign('current_mp', $this->current_mp);
    }
}